/*
 * parser use tokens to discren variable and consts in input filename and generate variales table in filename
 *
 * variable contains name, type, string value, int value
 * different type has different value
 */

#ifndef _parse_h
#define _parse_h
#include "token.h"
#include <string>
#include <sstream>
#include <vector>

struct variable {
    std::string name;
    tokentype type;
    std::string strvalue;
    int intvalue;

    variable(std::string name, tokentype type, std::string strvalue);
    variable(std::string name, tokentype type, int intvalue);
    variable(const variable& v);
    std::string get_str_value();
    int get_int_value();
    std::string to_string();
};

class parser {
private:
    int current;
    std::vector<token> tokens;
    std::string input;
    std::vector<variable> variables;

    char advance();
    char peek();
    std::string residu();
    bool isEnd();
    void parse_word(token tk);
    void parse_letter(token tk);
    void parse_digit(token tk);
    void parse_number(token tk);
    void parse_x(token tk);
    void parse_const(token tk);
    void parse_token(token tk);
public:
    parser(std::vector<token> tokens, std::string input);
    void parse();
    std::string to_string();
    std::vector<variable> get_variables();
};
std::vector<variable> parse(std::vector<token> tokens, std::string input);
#endif
